Условие:Вам даны две матрицы, нужно написать функцию для их умножения. Матрицы могут быть квадратными или прямоугольными.
Решение: Напишем решение на чистом Python
def matrix_multiply(A, B): # Сначала проверим, можем ли мы вообще перемножить эти матрицы if len(A[0]) != len(B): raise ValueError("Number of A columns must equal number of B rows.")
# Инициализируем результирующую матрицу, заполненную нулями result = [[0 for _ in range(len(B[0]))] for _ in range(len(A))]
# Перемножим матрицы for i in range(len(A)): for j in range(len(B[0])): for k in range(len(B)): result[i][j] += A[i][k] * B[k][j]
return result
# Проверим функцию на примере A = [[1, 2, 3], [4, 5, 6]]
B = [[7, 8], [9, 10], [11, 12]]
result = matrix_multiply(A, B) for row in result: print(row)
Условие:Вам даны две матрицы, нужно написать функцию для их умножения. Матрицы могут быть квадратными или прямоугольными.
Решение: Напишем решение на чистом Python
def matrix_multiply(A, B): # Сначала проверим, можем ли мы вообще перемножить эти матрицы if len(A[0]) != len(B): raise ValueError("Number of A columns must equal number of B rows.")
# Инициализируем результирующую матрицу, заполненную нулями result = [[0 for _ in range(len(B[0]))] for _ in range(len(A))]
# Перемножим матрицы for i in range(len(A)): for j in range(len(B[0])): for k in range(len(B)): result[i][j] += A[i][k] * B[k][j]
return result
# Проверим функцию на примере A = [[1, 2, 3], [4, 5, 6]]
B = [[7, 8], [9, 10], [11, 12]]
result = matrix_multiply(A, B) for row in result: print(row)
#программирование #линейная_алгебра
BY Библиотека собеса по Data Science | вопросы с собеседований
Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283
Some messages aren’t supposed to last forever. There are some Telegram groups and conversations where it’s best if messages are automatically deleted in a day or a week. Here’s how to auto-delete messages in any Telegram chat. You can enable the auto-delete feature on a per-chat basis. It works for both one-on-one conversations and group chats. Previously, you needed to use the Secret Chat feature to automatically delete messages after a set time. At the time of writing, you can choose to automatically delete messages after a day or a week. Telegram starts the timer once they are sent, not after they are read. This won’t affect the messages that were sent before enabling the feature.
Telegram announces Anonymous Admins
The cloud-based messaging platform is also adding Anonymous Group Admins feature. As per Telegram, this feature is being introduced for safer protests. As per the Telegram blog post, users can “Toggle Remain Anonymous in Admin rights to enable Batman mode. The anonymized admin will be hidden in the list of group members, and their messages in the chat will be signed with the group name, similar to channel posts.”
Библиотека собеса по Data Science | вопросы с собеседований from hk